package com.example.controller;

import com.example.entity.Orders;
import com.example.entity.OrdersCustom;
import com.example.service.OrdersCustomService;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @className OrdersCustomController
 * @Description TODO
 * @Author YUjiangpeng
 * @Date 2020/6/16 23:58
 * @Version 1.0
 **/
@RestController
public class OrdersCustomController {

    @Autowired
    private OrdersCustomService ordersCustomService;

    @Autowired
    private UserService userService;


    @ResponseBody
    @RequestMapping(value = "/order", method = RequestMethod.GET)
    public String testOrders(){
        List<OrdersCustom> ordersCustomsList = ordersCustomService.findOrdersUser();
        return ordersCustomsList.toString();
    }

    @ResponseBody
    @RequestMapping(value = "/order2", method = RequestMethod.GET)
    public String testOrdersByResultMap(){
        List<Orders> ordersList= ordersCustomService.findOrdersUserByResultMap();
        return ordersList.toString();
    }

    @ResponseBody
    @RequestMapping(value = "/order3", method = RequestMethod.GET)
    public String testOrdersByResultMapCollection(){
        List<Orders> ordersList= ordersCustomService.findOrdersAndOrderDetailResultMap();
        return ordersList.toString();
    }

    @ResponseBody
    @RequestMapping(value = "/batchInset", method = RequestMethod.GET)
    public String testBatchInsert(){

        List<Map<Object,Object>> list = new ArrayList<>();
        HashMap<Object, Object>  mp = new HashMap<>();
        mp.put("username","蔡文姬");
        mp.put("birthday",new Date());
        mp.put("sex","女");
        mp.put("addr","东方明珠");
        list.add(mp);
        HashMap<Object, Object>  mp2 = new HashMap<>();
        mp2.put("username","王昭君");
        mp2.put("birthday",new Date());
        mp2.put("sex","女");
        mp2.put("addr","世纪大厦");
        list.add(mp2);


         int j = userService.batchInsert(list);
        return  "success ? "+ j;
    }
}
